﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="false" CodeFile="recJurnalSummary.aspx.cs" Inherits="SIPO.Web.Lists.Transaction.recMonitoringPostJurnal" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body" Runat="Server">
 <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
     <script src="<%= ResolveUrl("~/scripts/helper.js") %>" type="text/javascript"></script>
    <script type="text/javascript">
        function pop() {
            alert("Under development proggress !");
        }
        function post(cellValue) {
            CallAjax('<%= ResolveUrl("~/ajaxhandler/transaction/recJurnalhandler.ashx") %>', '?method=update&id=' + cellValue);
            jQuery("#table").trigger("reloadGrid", [{ page: 1}]);
        }
     </script>
  <script type="text/javascript">
      $(document).ready(function () {

          $("#btnCancel").button({ icons: { primary: "ui-icon-close"} });
          $("#btnSubmit").button({ icons: { primary: "ui-icon-circle-arrow-e"} });

          $("#<%= txtPeriode1.ClientID %>").val('Periode Awal');
          $("#<%= txtPeriode2.ClientID %>").val('Periode Akhir');

          $("#btnCancel").click(function () {
              $("#<%= txtPeriode1.ClientID %>").val('Periode Awal');
              $("#<%= txtPeriode2.ClientID %>").val('Periode Akhir');

              $citys = $("#<%= ddlGroupPosting.ClientID %>");
              $citys.get(0).options.length = 0;

          });

          $("#<%= txtPeriode1.ClientID %>").datepicker({ showButtonPanel: true,
              changeMonth: true, changeYear: true, dateFormat: 'yymmdd',
              numberOfMonths: 1,
              //                onClose: function () {
              //                    $('#txtPeriodeAkhir').focus();
              //                },

              onSelect: function (selected) {
                  $("#<%= txtPeriode2.ClientID %>").datepicker("option", "minDate", selected);
                  $("#<%= txtPeriode2.ClientID %>").val('Periode Akhir');
              }
          });

          $("#<%= txtPeriode2.ClientID %>").datepicker({ showButtonPanel: true,
              changeMonth: true, changeYear: true, dateFormat: 'yymmdd',
              numberOfMonths: 1,
              onClose: function () {
                  // $('#txtPeriodeAkhir').focus();
                  var param = '?param=where_postingdate_between_\'' + $("#<%= txtPeriode1.ClientID %>").val() + '\'_and_\'' + $("#<%= txtPeriode2.ClientID %>").val() + "'";
                  $citys = $("#<%= ddlGroupPosting.ClientID %>");
                  $citys.get(0).options.length = 0;
                  var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/LoadPostGroup.ashx") %>';

                  $.ajax({
                      type: 'POST',
                      url: handlerUrl + param,
                      contentType: 'application/json',
                      dataType: 'json',
                      success: function (datas) {

                          if (datas.length > 1) {
                              $citys.get(0).options[0] = new Option("-- pilih group posting --", "");
                              $.each(datas, function (i, data) {
                                  $citys.append('<option value="' + data.PostingGroup + '">' + data.PostingGroup + '</option>');
                              });

                          } else if (datas.length == 1) {
                              $citys.append('<option value="' + datas[0].PostingGroup + '">' + datas[0].PostingGroup + '</option>');
                          }

                          $citys.trigger('chosen:updated');

                      },
                      error: function () {
                          alert('Error!');
                      }
                  });

              },

              onSelect: function (selected) {
                  $("#<%= txtPeriode1.ClientID %>").datepicker("option", "maxDate", selected)
              }
          });
          //          $("#btnPrint").click(function () {
          //              var formUrl = '<%= ResolveUrl("~/lists/Report/rptVoucherPrint.aspx") %>';

          //              var grid = $('#table');
          //              var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
          //                selText = [];
          //              $.each(selIds, function () {
          //                  selText.push(grid.jqGrid('getCell', this, 'BillingNo'));
          //              });
          //              if (selIds.length == 0) {
          //                  alert('Pilih data yang akan di cetak !');
          //              }
          //              else if (selIds.length > 1) {
          //                  alert('Pilih satu record untuk cetak voucher !');
          //              }
          //              else {
          //                  window.open(formUrl + "?id=" + selText);
          //              }
          //          });







          var handleUrl = 'nothing'; //agar saat load data tidak muncul
          var url1 = '<%= ResolveUrl("~/AjaxHandler/Transaction/recJurnalhandler.ashx") %>';
          $('#table').jqGrid({
              url: handleUrl,
              datatype: 'json',
              colNames: ['NoTrans', 'Transaksi', 'Group Transaksi', 'Tanggal Transaksi', 'Detail'],
              colModel: [
                { name: 'PostingGroup', hidden: true, index: 'PostingGroup', align: 'center', width: 200 },
           		{ name: 'CreatedBy', index: 'TranstypeName', align: 'left', width: 200 },
                { name: 'coaTypeNmae', index: 'CoaTypeName', align: 'left', width: 200 },
                { name: 'PostingDate', index: 'PostingDate', align: 'center', width: 115, formatter: 'date', formatoptions: { newformat: 'd M Y'} },
           	    { name: 'Detail', search: false, index: 'Detail', align: 'center', width: 85, formatter: linkDetail },
                         	],
              rowNum: 10,
              id: 'PostingGroup',
              multiselect: false,
              rowList: [5, 10, 15, 20],
              pager: '#pager',
              sortname: 'PostingDate',
              sortorder: "asc",
              viewrecords: true,
              jsonReader: { repeatitems: false },
              width: 750,
              height: '100%',
              caption: 'Summary Jurnal',
              ajaxGridOptions: { cache: false },
              subGrid: true,
              subGridRowExpanded: function (subgrid_id, row_id) {
                  var rowData = $("#table").getRowData(row_id);
                  var a = rowData['PostingGroup'];
                  // alert(url1 + '?method=getdatadetail&id=' + row_id);
                  var subgrid_table_id, pager_id;
                  subgrid_table_id = subgrid_id + "_t";
                  pager_id = "p_" + subgrid_table_id;
                  $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "'class='scroll'></table><div id='" + pager_id + "'class='scroll'></div>");
                  $("#" + subgrid_table_id).jqGrid({
                      url: url1 + '?method=getdatasummarydet&postgroup=' + a,
                      datatype: 'json',
                      mtype: 'POST',
                      colNames: ['Kode Rekening', 'Nama Rekening', 'Saldo Debet', 'Saldo Kredit', 'Posting Saiko'],
                      colModel: [
                        { name: "CodeAccount", index: "CodeAccount", width: 125, key: true, hide: true, align: "center" },
                      //                        {name:"recDemandDetail.TransNo",index:"TransNo",width:100},
                        {name: "coaTypeNmae", index: "bukubesarname", width: 150, align: "left" },
                        { name: 'SaldoDebet', index: 'SaldoDebet', formatter: 'currency', align: 'right', formatoptions: { decimalSeparator: ".", thousandsSeparator: ",", decimalPlaces: 2 }, width: 145 },
                       { name: 'Saldokredit', index: 'Saldokredit', formatter: 'currency', align: 'right', formatoptions: { decimalSeparator: ".", thousandsSeparator: ",", decimalPlaces: 2 }, width: 145 },
                        { name: "PostingGroup", index: "PostingGroup", width: 75, align: "center", formatter: linkPost }

                    ],
                      rowNum: 20,
                      // pager: pager_id,
                      sortname: 'CodeAccount',
                      sortorder: "asc",
                      viewrecords: true,
                      height: '100%'
                  });
                  //   $("#" + subgrid_table_id).jqGrid('navGrid', "#" + pager_id, { edit: false, add: false, del: false, search: false })
              }
              //              ondblClickRow: function () {
              //                  //                OpenForm('edit');
              //              }
          });



          function linkDetail(cellValue, rowdata) {
              var RestID = encodeURIComponent(cellValue);
              var id = cellValue;
              // alert(id);
              var invoice = rowdata['Pungutan_IDTransaksi'];
              // alert(invoice);
              //  return "<a  href='#' onclick=\"" + "pop('" + id + "')" + "\"" + ">Detail</a>";
              return "<a  href='#' onclick='pop()' >Detail</a>";
              //   return "<a href=\"" + "#" + "\"" + " onclick=\"" + "popupform('" + RestID + "','" + id + "','" + invoice + "')" + "\"" + ">" + RestID + "</a>";
          }


          function linkPost(cellValue, rowdata) {
              var id = rowdata['PostingGroup'];
              return "<a  href='#' onclick=\"" + "post('" + cellValue + "')" + "\"" + ">Posting</a>";
              //   return "<a href=\"" + "#" + "\"" + " onclick=\"" + "popupform('" + RestID + "','" + id + "','" + invoice + "')" + "\"" + ">" + RestID + "</a>";
          }


          $("#btnSubmit").click(function () {


              //              if (periodeawal.toString().toLowerCase().indexOf('awal') < 0 && periodeakhir.toString().toLowerCase().indexOf('akhir') < 0) {
              var posting = $("#<%= ddlGroupPosting.ClientID %>").val();
              if (posting == null) {
                  alert("Data filter tidak valid !");
                  return false;
              }
             
              jQuery("#table").setGridParam({ url: '<%= ResolveUrl("~/AjaxHandler/Transaction/recJurnalhandler.ashx") %>' + '?method=getdatasummary&posting=' + posting });
              jQuery("#table").trigger("reloadGrid", [{ page: 1}]);

              //              }
              //              
              //              else {
              //                  if (periodeawal.toString().toLowerCase().indexOf('2') < 0 && periodeakhir.toString().toLowerCase().indexOf('2') < 0) {

              //                      jQuery("#table").setGridParam({ url: '<%= ResolveUrl("~/AjaxHandler/Transaction/recJurnalhandler.ashx") %>' + '?method=getdata&periodeawal=&periodeakhir=' });
              //                      jQuery("#table").trigger("reloadGrid", [{ page: 1}]);
              //                  }
              //                  else  {
              //                      alert('Periode tanggal tidak valid !');
              //                  }
              //              }
          });

      });
    </script>
<table border="0">
<tr>
            <td style="width: 92px; text-align: left; height: 38px;">
           
                        Periode
                    </td>
            <td style="height: 38px; width: 15px;">
                        :
                    </td>
            <td align="left" style="height: 38px">
                <asp:TextBox ID="txtPeriode1" runat="server"></asp:TextBox>
&nbsp;s/d
                <asp:TextBox ID="txtPeriode2" runat="server"></asp:TextBox>       
&nbsp;<br />
            </td>

        </tr>
        <tr>
        <td style="width: 92px">
        Group Posting
        </td>
        <td>
        :
        </td>

        <td>
            <asp:DropDownList ID="ddlGroupPosting" runat="server" Height="22px" 
                Width="171px">
            </asp:DropDownList>
        </td>

        </tr>

        </table>
        <br />
     <button class="dialog_link ui-state-default ui-corner-all" id="btnSubmit" type="button">
                        Lanjut
                    </button>   
                     <button class="dialog_link ui-state-default ui-corner-all" id="btnCancel" type="button">
                        Batal
                    </button>
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0""  >
    
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog" title="Default dialog">
    </div>
    
     
</asp:Content>

